#include "Threadpool.hpp"

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include <iostream>

using std::cout;
using std::endl;

class MyTask
{
public:
    void process()
    {
        srand(time(NULL));
        int num = rand() % 100;
        cout << "worker thread " << pthread_self() << " produce a num:" << num << endl;
        sleep(1);//让每一个任务执行的时间设置为1秒
    }
};

int main()
{
    cout << "BO threadpool test()" << endl;
    wd::Threadpool threadpool(4, 10);
    threadpool.start();

    MyTask task;

    int cnt = 20;
    while(cnt-- > 0) {
        threadpool.addTask(std::bind(&MyTask::process, task));
        cout << "main thread cnt " << cnt << endl;
    }
    
    threadpool.stop();

    return 0;
}

